//
// Description: 1792. 最大平均通过率
// Created by Loading on 2023/2/19.
//

#include <bits/stdc++.h>

using namespace std;

double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
    // 自定义结构
    struct Ratio {
        // 通过人数，总人数
        int pass, total;
        // 重载运算符<
        bool operator < (const Ratio& r) const {
            double advance1 = 1.0 * (pass + 1) / (total + 1) - 1.0 * pass / total;
            double advance2 = 1.0 * (r.pass + 1) / (r.total + 1) - 1.0 * r.pass / r.total;
            // 通过率提升较大的班级排名靠前
            return advance1 < advance2;
        }
    };

    priority_queue<Ratio> q;
    for (auto &v : classes) {
        q.push({v[0], v[1]});
    }

    while (extraStudents--) {
        auto [pass, total] = q.top();
        q.pop();
        q.push({pass + 1, total + 1});
    }

    double res = 0;
    while (!q.empty()){
        auto [pass, total] = q.top();
        q.pop();
        res += 1.0 * pass / total;
    }

    return res / classes.size();
}

int main() {
    vector<vector<int>> classes = {{2, 4},
                                   {3, 9},
                                   {4, 5},
                                   {2, 10}};
    int extraStudents = 4;

    double res = maxAverageRatio(classes, extraStudents);

    cout << res << endl;

    return 0;
}